/**
 * 测试epoll ET和FT模式
 * @author: sundx
 * @date: 2020-05-12 07:51:24
 * @Last Modified by: sundx
 * @Last Modified time: 2020-05-12 16:39:53
 * g++ -std=c++11 -o test epoll_testETFT.cpp tcp_server_test.cpp
 */
#include "tcp_server_test.h"
int main() {
  sdx::TcpServer epollTestServer;
  epollTestServer.createSocket();
  epollTestServer.bindIp();
  epollTestServer.listenData();
  epoll_event events[EPOLL_EVENTS_SIZE];
  int epollFd = epoll_create(5);
  if (epollFd == -1) {
    std::cout << "epollFd create failed..." << std::endl;
    exit(EXIT_FAILURE);
  }
  epollTestServer.addEpollInFd(epollFd, epollTestServer.getListenFd(), true);
  std::cout << "add listenfd to epolltestserver success" << std::endl;
  while (true) {
    int ret = epoll_wait(epollFd, events, EPOLL_EVENTS_SIZE, -1);
    if (ret < 0) {
      std::cout << "epoll_wait failed..." << std::endl;
      break;
    }
    epollTestServer.EpollWorkInEt(events, ret, epollFd);
    // epollTestServer.EpollWorkInLt(events, ret, epollFd);
  }
  epollTestServer.closeSocket();
  return 0;
}